var  {merchants} =require('../../tools/database/index.js')
var PostData=require('../../tools/PostData/index.js')
module.exports=(async (req,res)=>{
	try{
		var userinfo=req.userinfo;
		var data= await PostData(req)
		var product=await merchants.warehouse.getDate(userinfo._id)
		// var commoditys=product.commodity.splice(data.index,1);
		var commoditys=product.commodity;
		var index=data.index;
		// commoditys.forEach(item=>{
		// 	if(item.title == data.title && )
		// })
		commoditys.splice(data.index,1)
		var result=await merchants.warehouse.upDate({
			"_id":userinfo._id
		},{
			"commodity":commoditys
		})
		res.send({
			state:200,
			msg:'下架成功'
		})
	}catch(e){
		res.send({
			state:404,
			msg:'未知错误'
		})
	}
})